<template>
  <transition name="el-zoom-in-top">
    <div v-if="visible" class="flex direction-column table-modal">
      <div class="padding flex justify-between table-modal-title">
        <span class="title-text">监管企业情况TOP10</span>
        <span class="close-button flex-center" :style="{color: themeColor}" @click="clickClose">
          <svg-icon name="arrow-left"></svg-icon>
        </span>
      </div>
      <div class="padding table-modal-head">
        <el-radio-group v-model="checked" @change="getTop10">
          <el-radio v-for="option in options" :key="option.value" :label="option.value">
            {{ option.label }}
          </el-radio>
        </el-radio-group>
      </div>
      <el-table
        v-loading="loading" :data="lists" height="100%" class="padding table"
        :header-cell-style="{backgroundColor: themeColor, color: 'white', textAlign: 'center'}"
      >
        <div slot="empty" class="empty-lists">
          <svg-icon name="search"></svg-icon>
          <span class="empty-text">暂无数据</span>
        </div>
        <el-table-column v-for="column in columns" :key="column.prop" v-bind="column"></el-table-column>
      </el-table>
    </div>
  </transition>
</template>

<script>
import DialogMixin from '@/mixins/dialog-mixin'
import { getListEnterprise } from '@/api/enterprose'

export default {
  name: 'table-modal',
  mixins: [DialogMixin],
  data () {
    return {
      checked: '1',
      options: [
        { label: '煤炭消费总量', value: '1' },
        { label: '产值单耗', value: '2' },
        { label: '能源消费总量', value: '3' },
      ],
      loading: false,
      lists: [],
      columns: [
        { label: '企业名称', prop: 'enterpriseName', width: 260 },
        { label: '消费总量', prop: 'total', align: 'center' },
        { label: '总量增速', prop: 'growth', align: 'center' },
        { label: '增速报警', prop: 'warning', align: 'center' },
      ]
    }
  },
  computed: {
    themeColor () {
      return this.$store.state.user.theme
    }
  },
  methods: {
    clickClose () {
      this.close()
    },
    open () {
      this.getTop10()
      this.visible = true
    },
    getTop10 () {
      this.loading = true
      // TODO
      getListEnterprise().then(res => {
        if (res.code === 200) {
          res.data.forEach(v => {
            v.total = '-'
            v.growth = '-'
            v.warning = '-'
          })
          this.lists = res.data
        }
      }).finally(() => {
        this.loading = false
      })
    },
  }
}
</script>

<style lang="scss" scoped>
  .table-modal {
    position: absolute;
    left: 10px;
    top: 10px;
    bottom: 10px;
    width: 600px;
    height: calc(100% - 20px);
    z-index: 110;
    background: rgba(255,255,255,0.9);
    border-radius: 6px;
    box-shadow: 0 0 16px 2px rgba(0,0,0,0.1);
  }
  .close-button {
    border: 1px solid currentColor;
    border-radius: 50%;
    width: 20px;
    height: 20px;
  }
  .table {
    background: transparent;
  }
</style>
